<template>
  <a-card :bordered="false">
    <!-- 抽屉 -->
    <a-drawer
      :title="itemName"
      :width="screenWidth"
      @close="onClose"
      :visible="visible"
    >
      <!-- 抽屉内容的border -->
      <div
        :style="{
          padding:'10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }">
        <div class="table-page-search-wrapper">
          <a-form layout="inline" :form="form" @keyup.enter.native="searchQuery">
            <a-row :gutter="10">
              <a-col :md="6" :sm="6">
                <a-form-item label="采集报表"  :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-search-select-tag
                    placeholder="请选择采集报表"
                    v-model="queryParam.tableCode"
                    dict="llbb_message_forms,reporttypename,reporttypecode"
                    :pageSize="null">
                  </j-search-select-tag>
                </a-form-item>
              </a-col>
              <a-col :md="4" :sm="4">
                <a-form-item label="生成状态"  :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    placeholder="请选择"
                    v-model="queryParam.sczt"
                  >
                    <a-select-option value="01">未生成</a-select-option>
                    <a-select-option value="02">生成成功</a-select-option>
                    <a-select-option value="03">生成失败</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="4" :sm="4">
                <a-form-item label="校验状态"  :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    placeholder="请选择"
                    v-model="queryParam.jyzt"
                  >
                    <a-select-option value="01">未校验</a-select-option>
                    <a-select-option value="02">校验通过</a-select-option>
                    <a-select-option value="03">校验完成有错</a-select-option>
                    <a-select-option value="04">校验完成异常</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="4" :sm="4">
                <a-form-item label="上报状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    placeholder="请选择"
                    v-model="queryParam.sbzt"
                  >
                    <a-select-option value="01">未上报</a-select-option>
                    <a-select-option value="02">上报成功</a-select-option>
                    <a-select-option value="03">上报失败</a-select-option>
                    <a-select-option value="04">强制上报</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="6">
              <span style="float: left;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery">搜索</a-button>
                <a-button type="primary" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </span>
              </a-col>
            </a-row>
          </a-form>
        </div>

        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button @click="itemRedort" type="primary" v-has="'quarterly:dayRepulse'" >重新生成</a-button>
          <!--          <a-button @click="itemCheck" type="primary" >批量校验</a-button>-->
          <!--          <a-button @click="itemDown" type="primary" v-has="'monthReport:itemDown'" >批量下载</a-button>-->
          <a-button @click="itemSourceDown" type="primary">批量下载源文件</a-button>
          <a-button @click="itemAfresh" type="primary"  v-has="'quarterly:itemAfresh'" >重新报送</a-button>
          <a-button @click="itemRepulse" type="primary" v-has="'quarterly:itemRepulse'" >打回</a-button>
        </div>

        <div>

          <a-table
            ref="table"
            size="middle"
            :scroll="{x:true}"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            class="j-table-force-nowrap"
            @change="handleTableChange">

            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
               <a @click="forceReport(record)" v-has="'monthReportItem:forceReport'">强制上报</a>
        </span>


          </a-table>

        </div>
      </div>
    </a-drawer>
    <ForceReport ref="forceReport" @ok="modalFormOk"></ForceReport>
    <j-modal
      :visible.sync="modal.visible"
      :width="600"
      :title="modal.title"
      :fullscreen.sync="modal.fullscreen"
      :switchFullscreen="modal.switchFullscreen"
    >

      <template v-for="(i,k) in dataList">
        <p :key="k">{{i.reporttypename}}</p>
      </template>

    </j-modal>

  </a-card>
</template>

<script>
import pick from 'lodash.pick'
import {filterObj} from '@/utils/util';
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {httpAction,downloadFile,getAction} from "@api/manage";
import ForceReport from '@views/llbb/report/dayReport/modules/ForceReport'

export default {
  name: "DictItemList",
  mixins: [JeecgListMixin],
  components: {
    ForceReport
  },
  data() {
    return {
      modal: {
        title: '未提交业务表',
        visible: false,
        fullscreen: false,
        switchFullscreen: false,
      },
      dataList:[],
      itemName:'',
      columns: [
        {
          title: '选项',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title: '报送任务日期',
          align: "center",
          dataIndex: 'REPORTTASKDATE',
        },
        {
          title: '数据日期',
          align: "center",
          dataIndex: 'DATADATE',
        },
        {
          title: '法人名称',
          align: "center",
          dataIndex: 'BANKNAME',
        },
        {
          title:'主题名称',
          align:"center",
          dataIndex: 'THEMENAME'
        },
        {
          title: '采集报表',
          align: "center",
          dataIndex: 'REPORTTYPENAME',
        },
        {
          title: '报文名称',
          align: "center",
          dataIndex: 'FILENAME',
        },
        {
          title: '当前分片数',
          align: "center",
          dataIndex: 'SEPARATESEQ',
        },
        {
          title: '生成状态',
          align: "center",
          dataIndex: 'CREATESTATE',
        },
        {
          title: '校验状态',
          align: "center",
          dataIndex: 'VERIFYSTATE',
        },
        {
          title: '上报状态',
          align: "center",
          dataIndex: 'REPORTSTATE',
        },
        {
          title: '审核打回',
          align: "center",
          dataIndex: 'REPONSESTATE',
        },
        {
          title: '报送标识',
          align: "center",
          dataIndex: 'REPORTFLAG',
        },
        {
          title: '报文生成时间',
          align: "center",
          dataIndex: 'CREATE_TIME',
        },
        {
          title: '操作时间',
          align: "center",
          dataIndex: 'UPDATE_TIME',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      queryParam: {
        dictId: "",
        dictName: "",
        itemText: "",
        delFlag: "1",
        status: [],
      },
      title: "操作",
      visible: false,
      screenWidth: 800,
      model: {},
      dictId: "",
      status: 1,
      labelCol: {
        xs: {span: 5},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 12},
        sm: {span: 12},
      },
      form: this.$form.createForm(this),
      validatorRules: {
        itemText: {rules: [{required: true, message: '请输入名称!'}]},
        itemValue: {rules: [{required: true, message: '请输入数据值!'}]},
      },
      url: {
        list: "/messagemanagement/llbbMessageManagement/findItemReportPageList",
        delete: "/sys/dictItem/delete",
        deleteBatch: "/sys/dictItem/deleteBatch",
      },
      pagam:{
        sjrq:[],
        bankNoCd:[],
        tableCode:[],
        sjdqps:[],
        frequency:'3',
      },
      checkPagam:{
        id:[]
      }
    }
  },
  created() {
    // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
    this.resetScreenSize();
  },
  methods: {
    forceReport(row){
      this.$refs.forceReport.add(row);
      this.$refs.forceReport.title = "强制上报";
    },
    searchReset() {
      let sjrq=this.queryParam.sjrq;
      let bankNoCd=this.queryParam.bankNoCd;
      this.queryParam = {};
      this.queryParam.sjrq=sjrq;
      this.queryParam.bankNoCd=bankNoCd;
      this.queryParam.frequency='3';
      this.loadData(1);
    },
    itemDown(){
      const that = this;
      if(this.selectedRowKeys.length==0){
        that.$message.warning("请选择你要批量下载的数据");
        return false;
      }
      for(var i=0;i<this.selectedRowKeys.length;i++){
        this.checkPagam.id[i]=this.dataSource[this.selectedRowKeys[i]].ID;
      }
      that.onClearSelected();
      let url=`${window._CONFIG['domianURL']}`+"/messagemanagement/llbbMessageManagement/itemDownLoad?id[]="+ this.checkPagam.id;
      window.location.href=url;
      /*let url="/messagemanagement/llbbMessageManagement/itemDownLoad";
      let data=new Date();
      downloadFile(url,data.getTime()+".zip",this.checkPagam);*/
      setTimeout(function(){
        that.loadData(1);
      },3000);
    },
    itemSourceDown(){
      const that = this;
      if(this.selectedRowKeys.length==0){
        that.$message.warning("请选择你要批量下载的数据");
        return false;
      }
      var bool=false;
      for(var i=0;i<this.selectedRowKeys.length;i++) {
        if(this.dataSource[this.selectedRowKeys[i]].CREATESTATE=='未生成'){
          bool=true;
          break;
        }
      }
      if(bool){
        that.$message.warning("只能选择生成成功的数据");
        return;
      }
      for(var i=0;i<this.selectedRowKeys.length;i++) {
        this.checkPagam.id[i]=this.dataSource[this.selectedRowKeys[i]].ID;
      }
      that.onClearSelected();
      let url=`${window._CONFIG['domianURL']}`+"/messagemanagement/llbbMessageManagement/itemSourceDown?id[]="+ this.checkPagam.id;
      window.location.href=url;
      setTimeout(function(){
        that.loadData(1);
      },3000);
    },
    itemAfresh(){
      const that = this;
      if(this.selectedRowKeys.length==0){
        that.$message.warning("请选择你要重新报送的数据");
        return false;
      }
      for(var i=0;i<this.selectedRowKeys.length;i++){
        this.checkPagam.id[i]=this.dataSource[this.selectedRowKeys[i]].ID;
      }
      this.loading = true;
      getAction("/messagemanagement/llbbMessageManagement/itemAfresh",this.checkPagam).then((res)=>{
        that.onClearSelected();
        this.loading = false;
        if(res.success){
          that.$message.success(res.message);
          this.loadData(1);
        }else{
          that.$message.warning(res.message);
        }
      }).finally(() => {

      })
    },
    itemRepulse(){
      const that = this;
      if(this.selectedRowKeys.length==0){
        that.$message.warning("请选择你要打回的数据");
        return false;
      }
      for(var i=0;i<this.selectedRowKeys.length;i++){
        this.checkPagam.id[i]=this.dataSource[this.selectedRowKeys[i]].ID;
      }
      this.loading = true;
      getAction("/messagemanagement/llbbMessageManagement/itemRepulse",this.checkPagam).then((res)=>{
        that.onClearSelected();
        this.loading = false;
        if(res.success){
          that.$message.success(res.message);
          this.loadData(1);
        }else{
          that.$message.warning(res.message);
        }
      }).finally(() => {

      })
    },
    itemCheck(){
      const that = this;
      if(this.selectedRowKeys.length==0){
        that.$message.warning("请选择你要批量校验的数据");
        return false;
      }
      for(var i=0;i<this.selectedRowKeys.length;i++){
        this.checkPagam.id[i]=this.dataSource[this.selectedRowKeys[i]].ID;
      }
      this.loading = true;
      getAction("/messagemanagement/llbbMessageManagement/itemCheck",this.checkPagam).then((res)=>{
        that.onClearSelected();
        this.loading = false;
        if(res.success){
          that.$message.success(res.message);
          this.loadData(1);
        }else{
          that.$message.warning(res.message);
        }
      }).finally(() => {

      })
    },
    itemRedort(){
      const that = this;
      if(this.selectedRowKeys.length==0){
        that.$message.warning("请选择你要重新生成的数据");
        return false;
      }
      for(var i=0;i<this.selectedRowKeys.length;i++){
        this.pagam.sjrq[i]=this.dataSource[this.selectedRowKeys[i]].DATADATE;
        this.pagam.bankNoCd[i]=this.dataSource[this.selectedRowKeys[i]].BANK_NO_CD;
        this.pagam.tableCode[i]=this.dataSource[this.selectedRowKeys[i]].REPORTTYPECODE;
        this.pagam.sjdqps[i]=this.dataSource[this.selectedRowKeys[i]].SEPARATESEQ;
      }
      let url="/messagemanagement/llbbMessageManagement/itemRedort";
      this.loading = true;
      getAction(url,this.pagam).then((res)=>{
        that.onClearSelected();
        this.loading = false;
        if(res.success){
          that.$message.success(res.message);
          this.loadData(1);
        }else{
          if(res.result==null){
            that.$message.open(res.message);
          }else{
            if(res.result==null){
              that.$message.error(res.message);
            }else if(res.code == 501){
              this.dataList=res.result;
              this.modal.title='未提交业务表'
              this.modal.visible=true;
            }else if(res.code == 502){
              this.dataList=res.result;
              this.modal.title='未表间校验业务表'
              this.modal.visible=true;
            }
          }
        }
      }).finally(() => {

      })
    },
    add(dictId) {
      this.dictId = dictId;
      this.edit({});
    },
    edit(record) {
      this.itemName="月报报文 "+record.BANKNAME+" "+record.DATADATE+" 数据明细";
      if (record.id) {
        this.dictId = record.id;
      }
      this.queryParam = {};
      this.queryParam.sjrq= record.DATADATE;
      this.queryParam.bankNoCd=record.BANKCODE;
      this.queryParam.theme=record.THEME;
      this.queryParam.frequency='3';
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.model.dictId = this.dictId;
      this.model.status = this.status;
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, 'itemText', 'itemValue'))
      });
      // 当其它模块调用该模块时,调用此方法加载字典数据
      this.loadData();
    },

    getQueryParams() {
      //update--begin--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      this.ipagination.total=0;
      //update--end--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      var param = Object.assign({}, this.queryParam);
      param.dictId = this.dictId;
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param);
    },

    // 添加字典数据
    handleAdd() {
      this.$refs.modalForm.add(this.dictId);
      this.$refs.modalForm.title = "新增";
    },
    showDrawer() {
      this.visible = true
    },
    onClose() {
      this.visible = false
      this.form.resetFields();
      this.dataSource = [];
    },
    // 抽屉的宽度随着屏幕大小来改变
    resetScreenSize() {
      let screenWidth = document.body.clientWidth;
      if (screenWidth < 600) {
        this.screenWidth = screenWidth;
      } else {
        this.screenWidth = 600;
      }
      this.screenWidth = '100%';
    },
    //update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
    //增加样式方法返回值
    getRowClassname(record){
      if(record.status==0){
        return "data-rule-invalid"
      }
    }
    //update--end--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
  }
}
</script>
<style lang="less" scoped>
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
/deep/ .data-rule-invalid{
  background: #f4f4f4;
  color: #bababa;
}
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
</style>